//
//  CAReturnGoodsDetailGoodsView.m
//  LNH
//
//  Created by twentylx on 2018/2/26.
//  Copyright © 2018年 twentylx. All rights reserved.
//

#import "CAReturnGoodsDetailGoodsView.h"

@implementation CAReturnGoodsDetailGoodsView

/**
 为视图绑定 viewModel
 
 @param viewModel 要绑定的ViewModel
 @param params 额外参数
 */
- (void)bindViewModel:(id <LMViewProtocol>)viewModel withParams:(NSDictionary *)params {
    
}

/**
 初始化额外数据
 */
- (void)lm_initializeForView {
    self.backgroundColor = [UIColor whiteColor];
}

/**
 初始化视图
 */
- (void)lm_createViewForView {
    [self setNeedsUpdateConstraints];
    
    [self addSubview:self.topLineView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.lineView];
    [self addSubview:self.goodsImageView];
    [self addSubview:self.nameLabel];
    [self addSubview:self.sizeLabel];
}

#pragma mark layout
- (void)updateConstraints {
    [super updateConstraints];
    
    [_topLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self);
        make.top.equalTo(self);
        make.height.mas_equalTo(ONE_PIXEL);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(20);
        make.top.equalTo(self).offset(10);
    }];
    
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(10);
        make.height.mas_equalTo(ONE_PIXEL);
    }];
    
    [_goodsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(20);
        make.top.equalTo(self.lineView.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(80, 80));
    }];
    
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.goodsImageView.mas_right).offset(20);
        make.top.equalTo(self.goodsImageView);
        make.right.equalTo(self).offset(-20);
    }];
    
    [_sizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel);
        make.centerY.equalTo(self.goodsImageView);
        make.right.equalTo(self).offset(-20);
    }];
}

#pragma mark get & set
- (UIView *)topLineView {
    if (!_topLineView) {
        _topLineView = [UIView new];
        _topLineView.backgroundColor = RGBCOLOR(241, 241, 241);
    }
    return _topLineView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont systemFontOfSize:16];
    }
    return _titleLabel;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = RGBCOLOR(241, 241, 241);
    }
    return _lineView;
}

- (UIImageView *)goodsImageView {
    if (!_goodsImageView) {
        _goodsImageView = [UIImageView new];
    }
    return _goodsImageView;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [UILabel new];
        _nameLabel.numberOfLines = 3;
        _nameLabel.lineBreakMode = NSLineBreakByCharWrapping;
        _nameLabel.font = [UIFont systemFontOfSize:14];
    }
    return _nameLabel;
}

- (UILabel *)sizeLabel {
    if (!_sizeLabel) {
        _sizeLabel = [UILabel new];
        _sizeLabel.font = [UIFont systemFontOfSize:14];
        _sizeLabel.numberOfLines = 2;
        _sizeLabel.lineBreakMode = NSLineBreakByCharWrapping;
    }
    return _sizeLabel;
}

@end

